<?php

require_once 'phpmoko/externals/JPhpMoko.php';
require_once 'phpmoko/ui/Widget.php';
require_once 'phpmoko/ui/Label.php';

class TabBar extends Widget
{
	private $texts = array();
	private $selected = -1;

	function __construct()
	{
		parent::__construct();

		$this->setId(RootPanel::getUniqueId());

//		JQueryUI::activate();

		JPhpMoko::activate();
	}

	function addTab($text)
	{
		$this->texts[] = $text;
	}

	function selectTab($index)
	{
		$this->selected = $index;
	}

	function toString()
	{
		$widgets = array();
		foreach ($this->texts as $key => $value)
			$widgets[] = new Hyperlink($value, '#'.$this->id.'-'.($key + 1));

		$str = '<table class="pmk-TabBar" cellspacing="0" cellpadding="0" role="tablist" id="'.$this->id.'-TabBar">';

		$str .= '<tr>';

		$str .= '<td class="pmk-TabBarFirst-wrapper" height="100%" align="left" style="vertical-align: bottom;">';
		$str .= '<div class="pmk-TabBarFirst" style="white-space: normal; height: 100%;"> </div>';
		$str .= '</td>';

		for ($i = 0; $i < count($widgets); $i++)
		{
			$str .= '<td class="pmk-TabBarItem-wrapper" align="left" style="vertical-align: bottom;">';
			$str .= '<div class="pmk-TabBarItem';
			if ($this->selected  == $i)
				$str .= ' pmk-TabBarItem-selected';

			$str .= '" tabindex="0" role="tab">';
			$str .= $widgets[$i]->toString();
			$str .= '</div>';
			$str .= '</td>';
		}

		$str .= '<td class="pmk-TabBarRest-wrapper" align="left" width="100%" style="vertical-align: bottom;">';
		$str .= '<div class="pmk-TabBarRest" style="white-space: normal; height: 100%;"> </div>';
		$str .= '</td>';
			
		$str .= "</tr>";

		$str .= "</table>";

		$str .= '<script type="text/javascript"> $("#'.$this->id.'-TabBar").phpmokotabbar(); </script>';

		return $str;
	}
}
?>